package com.example.myapp61.Util;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.widget.Toast;

import java.util.HashMap;
import java.util.Map;

public class ShareUtil {
    public static void save(Context context,String key,String param2){
        SharedPreferences sp = context.getSharedPreferences("shareDB", Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putString(key,param2);
        editor.commit();
        Toast.makeText(context,"信息写入了",Toast.LENGTH_SHORT).show();
    }
    public static Map<String, String> read(Context context,String key){
        Map<String, String> data = new HashMap<>();
        SharedPreferences sp = context.getSharedPreferences("shareDB", Context.MODE_PRIVATE);
        data.put(key,sp.getString(key,""));
        return data;
    }

    /**
     *
     * @param context
     * @param key
     * @param params  当key不存在时返回的值
     * @return
     */
    public static boolean getBoolean(Context context,String key,boolean params) {
        SharedPreferences sp = context.getSharedPreferences("shareDB", Context.MODE_PRIVATE);
        return sp.getBoolean(key,params);
    }

    public static void putBoolean(Context context,String key,Boolean param) {
        SharedPreferences sp = context.getSharedPreferences("shareDB",Context.MODE_PRIVATE);
        Editor editor = sp.edit();
        editor.putBoolean(key,param);
        editor.commit();
        ToasUtil.showMes(context,"启动记录成功");
    }
}
